<?php
/**
 * include our autoloader
 */
include('../autoload.php');

$options = array('limit' => 5);

/**
 * example retrieve all records
 * from a table using options array
 */
echo '<h3>Example of retrieveAll</h3>';
echo '<pre>'.print_r($options, true).'</pre>';
$allLines = SwiftORM::getTable('PcdbSku')->retrieveAll($options);
foreach ($allLines as $lineObj)
{
    echo 'ID: '.$lineObj->getSkuID().' (order: '.$lineObj->getSkuDisplayOrder().')<br />';
}

/**
 * same as above but with ordering
 */
echo '<h3>Example of retrieveAll with ordering</h3>';
$options['order_by'] = 'SkuDisplayOrder ASC';
echo '<pre>'.print_r($options, true).'</pre>';
$allLines = SwiftORM::getTable('PcdbSku')->retrieveAll($options);
foreach ($allLines as $lineObj)
{
    echo 'ID: '.$lineObj->getSkuID().' (order: '.$lineObj->getSkuDisplayOrder().')<br />';
}

/**
 * example retrieving by single field
 */
echo '<h3>Example of retrieve by specific field</h3>';
echo '<pre>'.print_r($options, true).'</pre>';
$specificLines = SwiftORM::getTable('PcdbSku')->retrieveBySkuSize('28/R', $options);
foreach ($specificLines as $lineObj)
{
    echo 'ID: '.$lineObj->getSkuID().' (size: '.$lineObj->getSkuSize().', order: '.$lineObj->getSkuDisplayOrder().')<br />';
}

/**
 * same as above with offset
 */
echo '<h3>Example of retrieve by specific field with offset</h3>';
$options['offset'] = 5;
echo '<pre>'.print_r($options, true).'</pre>';
$specificLines = SwiftORM::getTable('PcdbSku')->retrieveBySkuSize('28/R', $options);
foreach ($specificLines as $lineObj)
{
    echo 'ID: '.$lineObj->getSkuID().' (size: '.$lineObj->getSkuSize().', order: '.$lineObj->getSkuDisplayOrder().')<br />';
}

/**
 * retrieve single record edit a 
 * value and save it
 */
echo '<h3>Example of setting a value and saving</h3>';
$lineObj = SwiftORM::getTable('PcdbSku')->retrieveBySkuID(281320);
$lineObj->setSkuSize($lineObj->getSkuSize());
$lineObj->setSkuDisplayOrder($lineObj->getSkuDisplayOrder);
$lineObj->save();
echo 'Done.';
?>
